import java.util.*;
import java.util.Map;

public class Demo1 {

    public static void main(String[] args) {
        //创建Map集合

        Map<String,String> map=new HashMap<>();

        map.put("cn","中国");
        map.put("1","蒋恬");
        map.put("2","陈海圣");

        System.out.println("map长度为"+map.size());
        System.out.println(map);

        //遍历【重点】
        System.out.println("------使用keyset遍历-----");
        Set<String> keyset=map.keySet();
        for (String key:keyset)
        {
            System.out.println(key);
        }

        System.out.println("------加强for遍历-----");
        for (Object key :
                map.keySet()) {
            System.out.println(key);
        }

        System.out.println("------------使用entrySet遍历");
      //  Set<Map.Entry<String,String>> entries=map.entrySet();
        for (Map.Entry<String,String>entry:map.entrySet())
        {
            System.out.println(entry.getKey()+"---------"+entry.getValue());
        }


        //判断指定key value是否存在
        System.out.println(map.containsKey("cn"));
        System.out.println(map.containsValue("中国"));
    }
}
